/**
 * index
 */
define(function(require) {
    var $ = require('jquery');
    var com = require('./common');



    require('lib/vue');
    require('lib/axios');
    var qs = require('lib/qs');

    

    //全局配置
    axios.interceptors.request.use(function(config){
        //在请求发出之前进行一些操作
        if(config.method  === 'post'){
            config.data = qs.stringify(config.data);
        };
        return config;
    },function(error){
        // Do something with request error
        return Promise.reject(error);
    });

    axios.interceptors.response.use(function(response){
        return response;
    },function(error){
        alert('数据请求失败，请刷新页面重试！');
        //console.warn(error.response);
        return Promise.reject(error.response.data)
    });



    //get方法
    axios.get('/test/test.json', {params:{kcid:'123',zid:'456',jid:'789'}}).then(function(response){ 
        //success callback
        console.warn(response.data);
    }).catch(function (error) {
        //error callback
        console.warn(error);
    });


    //post方法
    axios.post('/test/test.json', {kcid:'123',zid:'456',jid:'789'}).then(function(response){ 
        //success callback
        console.warn(response.data);
    }).catch(function (error) {
        //error callback
        console.warn(error);
    });




    var vue_newCourse = new Vue({
        el:'#vue_newCourse',
        data:{
            tab:0,
            data_new:'',
            data_hot:''
        },
        methods:{
            tab_change:function(n){
                this.tab = n;
            },
            initNewCourse: function(){
                var _this = this;
                //最新课程
                axios.get('/test/test.json',{params:{limit:4,sort: 'input_time DESC'}}).then(function(response){ //success callback
                    var result = response.data;
                    _this.data_new = result.data;
                });
            },
            initHotCourse: function(){
                var _this = this;
                //最热课程
                axios.get('/test/test1.json',{params:{limit:4,sort: 'xxrs DESC,input_time DESC'}}).then(function(response){ //success callback
                    var result = response.data;
                    _this.data_hot = result.data;
                });
            }
        },
        created:function(){
            this.$nextTick(function(){
                this.initNewCourse();
                this.initHotCourse();
            })
        }
    });

    


    
});